import numpy
import SimpleITK as sitk

fixed=sitk.ReadImage('Data/0.nii')
fixed = sitk.Cast(fixed ,sitk.sitkFloat32)

moving=sitk.ReadImage('Data/3.nii')
moving= sitk.Cast(moving,sitk.sitkFloat32)

demons = sitk.DemonsRegistrationFilter()
demons.SetNumberOfIterations(4)#200
demons.SetStandardDeviations(1)

displacementField = demons.Execute(fixed, moving)
print(demons.GetMetric())
print(displacementField.GetPixel(0,0,0))#vec0
print(displacementField.GetPixel(1,0,0))#vec1
print(displacementField.GetPixel(0,1,0))#vec 343x3
print(displacementField.GetPixel(0,0,1))
outTx = sitk.DisplacementFieldTransform(displacementField)
sitk.WriteTransform(outTx, 'x4.mat')#guass format:(x1,y1,z1),(x2,y2,z2),etc..
# print(displacementField.GetSize())
'''print(displacementField.GetPixel(0,0,0))'''
# pos=numpy.loadtxt('posInt6Array.txt',dtype=int)#numpy.ndarray
#print(pos.shape) #(226,3)
# [rows,cols]=pos.shape
# field=sitk.GetArrayFromImage(displacementField)
# print(field[100,100,100])
